//
//  LoginViewController.m
//  NuanMao
//
//  Created by 绿水 on 16/2/24.
//  Copyright © 2016年 MJ. All rights reserved.
//

#import "LoginViewController.h"
#import "barItem.h"
#import "loginIVew.h"
#import <AFHTTPSessionManager.h>
#import 
#define KleftWidth 10
#define KTopHeight (64+20)
#define KLaleHeight 44
#define KTextFiledLable 20//textFiled与lable间隔

typedef NS_ENUM(NSInteger,textFieledTag){
    //textFiledTag值
    KNanmeTFtg = 10,
    KPasswordTag,
};

@interface LoginViewController ()
{
    //表控制器对象
    loginIVew *_loginv;
}

@property(nonatomic,copy)NSString *userName;
@property(nonatomic,copy)NSString *passWord;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //添加导航条
    self.view.backgroundColor = [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1];
    
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    
    [self addBarButtonItem];

    _loginv = [[loginIVew alloc]init];
    [self.view addSubview:_loginv.view];
    

    //退出按钮(测试)
     UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(100, 200, 100, 40);
    [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    button.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:button];

    
}

-(void)btnClick:(UIButton *)sender
{

    
    
}

-(void)addBarButtonItem
{
    self.navigationItem.rightBarButtonItems = [barItem barButtonItem:@[@"完成"] target:self action:@selector(doneBtnClick:)];
}
#pragma mark - 导航条按钮
-(void)doneBtnClick:(UIBarButtonItem *)sender
{
    
  UITextField *nameFiled = (UITextField *)[ _loginv.view viewWithTag:KNanmeTFtg];
    
    UITextField *passWordFiled = (UITextField *)[_loginv .view viewWithTag:KPasswordTag];

    NSLog(@"%@",nameFiled.text);
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"ext/html"];
    [manager POST:@"http://101.201.171.239/MobileMall/login" parameters:@{@"username":nameFiled.text,@"password":passWordFiled.text,@"pageIndex":@"1",@"mallId":@"44"} success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        NSLog(@"%@",responseObject);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"%@",error);
    }];
    
    
    
}





@end
